package ringbuffer;
import com.lmax.disruptor.RingBuffer;

public class MsgEventProducer {
	private final RingBuffer<MsgEvent> ringBuffer;

	public MsgEventProducer(RingBuffer<MsgEvent> ringBuffer) {
		this.ringBuffer = ringBuffer;
	}

	public void onData(String msg) {
		long sequence = ringBuffer.next(); // Grab the next sequence
		try {
			MsgEvent event = ringBuffer.get(sequence); // Get the entry in the
			event.set(msg); // Fill with data
		} finally {
			ringBuffer.publish(sequence);
		}
	}
}